<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%!
	public Map getMap(List<Map> result , Map<String,String> deptMap){
		int sumCount = 0;
		//处理结合数据
		for(Map map : result){
		
			String count = map.get("count") == null ? "0" : map.get("count").toString();
		
			String ksdm = map.get("ksdm") == null ? "0" : map.get("ksdm").toString();
			map.put("name",deptMap.get(ksdm));
			map.put("cont",map.get("count"));
			sumCount = sumCount + Integer.parseInt(count);
		}
		
		Map<String,Object> resMap = new HashMap<String,Object>();
		resMap.put("rank",result);
		resMap.put("sumCount",sumCount+"");
		return resMap;
	}
%>
<%
	//统计住院患者明细
	String date = input.getDesc("start_date","2016-12-10");//开始时间
	String endDa = input.getDesc("end_date","2017-12-21");//结束时间
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";
	
	//获取所有科室
	List<Map> deptList = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from his_dept ");
	Map<String,String> deptMap = new HashMap<String,String>();
	//科室放到map中 key-value(id-name)
	for(Map map : deptList){
		deptMap.put(map.get("id").toString(),map.get("name").toString());
	}
	
	
	//入院相当于 这个区间入院的
	String hql = "select new map(a.patid as patid , a.hzxm as hzxm ,a.sex as sex , a.ksdm as ksdm , a.ryrq as ryrq ,a.wzjb as wzjb ,a.memo as memo ,a.cyzdmc as cyzdmc ) from ZY_BRSYK a , ZY_BRXXK b where a.patid = b.patid and  ryrq >= '" + startDate + "' and ryrq <= '" + endDate + "'   order by ryrq desc";
	List<Map> result = QBuilder.db("basedb").queryHql(hql);
	
	
	
	Map<String,Object> resMap = new HashMap<String,Object>();
	resMap.put("ryMap",getMap(result , deptMap));
	
	Message msg = new Message();
	
	msg.put("inpatient",resMap);
	out.println(msg);
%>